package com.gzmu.storage.mapper;

import com.gzmu.storage.entity.Permission;
import com.gzmu.storage.entity.Role;
import com.gzmu.storage.entity.User;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-04-16
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from t_user where username=#{username}")
    User getUserByUserName(@Param( "username" ) String username);

    @Select( "SELECT r.* FROM t_user u,t_user_role ur,t_role r WHERE u.id=ur.role_id AND ur.role_id=r.id AND u.username=#{username}" )
    List<Role> getRolesByUserName(@Param( "username" ) String username);

    @Select( "SELECT p.* FROM t_user u,t_user_role ur,t_role_permission rp,t_permission p WHERE u.id=ur.user_id and " +
            "ur.role_id=rp.role_id and rp.permission_id=p.id and u.username=#{username}" )
    List<Permission> getPermissionsByUserName(@Param( "username" ) String username);
}
